package hisp;

import java.io.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class AuditLog {

	
	public void writeLog(Identity identity, String interaction){
		
		BufferedWriter audit = null;
		
		try{
			
			FileWriter filewriter = new FileWriter("auditlog.txt", true);
			audit = new BufferedWriter(filewriter);
			
			String log = identity.id + " ";
			
			log += interaction + " ";
			

	        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	        Date date = new Date();
	        
	        log += dateFormat.format(date);

	        
			audit.write(log);
			audit.newLine();
			audit.flush();
			
		
		} catch (Exception e){
			e.printStackTrace();
		} finally {
			if (audit != null){ 
				try{
					audit.close();
				}catch ( Exception e){
					
				}
			}
			
		}
	}
}